﻿using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;

namespace Gmantis.Controls.Extended
{
    public interface ITypeEditor
    {
        string DataField { get; set; }
        object Value { get; set; }
    }

    public class Form : UserControl
    {
        // Fields
        private static IsolatedStorageSettings _userconfig = IsolatedStorageSettings.ApplicationSettings;

        // Methods
        public Dictionary<string, object> SaveData()
        {
            Dictionary<string, object> data = new Dictionary<string, object>();
            foreach (FrameworkElement element in FormHelper.GetChildObjects<FrameworkElement>(this))
            {
                if (!(element is ITypeEditor))
                    continue;

                ITypeEditor editor = (ITypeEditor)element;
                if (!string.IsNullOrEmpty(editor.DataField) && editor.Value != null)
                    data.Add(editor.DataField, editor.Value);
            }
            return data;
        }

        // Properties
        public static IsolatedStorageSettings UserConfig
        {
            get { return _userconfig; }
            set { _userconfig = value; }
        }
    }
}
